package cn.doitedu.rules.utils;

import cn.doitedu.rules.pojo.EventParam;
import cn.doitedu.rules.pojo.RuleCondition;
import org.apache.commons.collections.map.HashedMap;
import org.jcodings.util.Hash;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 获取一个模拟的规则，以后是使用Drools规则引擎的规则
 */
public class RulesSimulator {

    public static RuleCondition getRules() {

        //模拟一个规则
        RuleCondition condition = new RuleCondition();
        condition.setRuleId("my-rule-00001");

        //模拟触发的事件
        EventParam eventParam = new EventParam();
        //预设触发事件为K
        eventParam.setEventId("K");
        //预设条件属性
        HashMap<String, String> eventProps = new HashMap<String, String>();
        eventProps.put("p2", "v1");
        eventProps.put("p3", "v3");
        eventParam.setProperties(eventProps);
        condition.setTriggerEvent(eventParam);

        //模拟画像标签和值
        HashMap<String, String> userProfile = new HashMap<>();
        //预设画像标签和值
        userProfile.put("tag26", "v1");
        userProfile.put("tag87", "v1");
        condition.setUserProfileCondition(userProfile);

        //模拟查询ClickHouse的查询条件
        ArrayList<EventParam> clickHouseEventParams = new ArrayList<>();
        EventParam chEventParam1 = new EventParam();
        //预设查询clickhouse历史库的条件
        chEventParam1.setEventId("K");
        HashMap<String, String> chEventParam1Map = new HashMap<>();
        chEventParam1Map.put("p1", "v2");
        chEventParam1Map.put("p5", "v1");
        chEventParam1.setProperties(chEventParam1Map);
        chEventParam1.setThreshCount(2);
        chEventParam1.setStartTime(1630425600000L);
        chEventParam1.setEndTime(1630943999000L);
        chEventParam1.setSql("select count(1) from zenniu_detail where deviceId = ? and eventId = ? and timeStamp >= ? and timeStamp <= ? ");
        clickHouseEventParams.add(chEventParam1);
        condition.setUserActionCountCondition(clickHouseEventParams);

        return condition;
    }
}
